package com.init.bootframe.business.controller;

import com.init.bootframe.business.service.IContactService;
import com.init.bootframe.business.service.IProductService;
import com.init.bootframe.business.vo.ContactVO;
import com.init.bootframe.business.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService; //产品service

    @Autowired
    private IContactService contactService; //公司联系信息service

    /**
     * 分页查询产品列表数据
     * @param productVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findProductList")
    public Map<String, Object> findProductList(@RequestBody ProductVO productVO) throws Exception {
        Map<String, Object> result = productService.findProductList(productVO);
        return result;
    }

    /**
     * 后台查询产品list列表数据
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping("/findProductsList")
    public List<ProductVO> findProductsList() throws Exception {
        ProductVO product = new ProductVO();
        return productService.findProduct(product);
    }

    /**
     * 查询产品详情
     * @param productVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findProducts")
    public ProductVO findProducts(@RequestBody ProductVO productVO) throws Exception {
        ProductVO result = productService.findProducts(productVO);
        return result;
    }

    /**
     * 添加产品
     * @param productVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addProduct")
    public Map<String, Object> addProduct(@RequestBody ProductVO productVO) throws Exception {
        Map<String, Object> result = productService.addProduct(productVO);
        return result;
    }

    /**
     * 修改产品
     * @param productVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateProduct")
    public Map<String, Object> updateProduct(@RequestBody ProductVO productVO) throws Exception {
        Map<String, Object> result = productService.updateProduct(productVO);
        return result;
    }

    /**
     * 删除产品
     * @param productVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteProduct")
    public Map<String, Object> deleteProduct(@RequestBody ProductVO productVO) throws Exception {
        Map<String, Object> result = productService.deleteProduct(productVO);
        return result;
    }



    /**
     * 查询产品list列表数据
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping("/webs/findProductLists")
    public Map<String, Object> findProductLists(@RequestBody ProductVO productVO) throws Exception {
        Map<String, Object> result = new HashMap<>();
        // 公司联系信息
        List<ContactVO> contactList = contactService.findContact();
        // 产品
        List<ProductVO> productList = productService.findProduct(productVO);
        result.put("product",productList);
        result.put("contant",contactList.get(0));
        return result;
    }

    /**
     * 查询产品详情
     * @param productVO
     * @return
     * @throws Exception
     */
    @PostMapping("/webs/findWebProducts")
    public Map<String, Object> findWebProducts(@RequestBody ProductVO productVO) throws Exception {
        Map<String, Object> result = new HashMap<>();
        // 产品详情
        ProductVO product = productService.findProducts(productVO);
        // 公司联系信息
        List<ContactVO> contactList = contactService.findContact();
        result.put("product",product);
        result.put("contant",contactList.get(0));
        return result;
    }

}
